package com.yf.zzmusic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yf.zzmusic.common.PageInfo;
import com.yf.zzmusic.common.Result;
import com.yf.zzmusic.pojo.dto.followSinger.FansPageDTO;
import com.yf.zzmusic.pojo.dto.followSinger.FollowSingerPageDTO;
import com.yf.zzmusic.pojo.entity.User;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.yf.zzmusic.service.IFollowSingerService;
import com.yf.zzmusic.pojo.entity.FollowSinger;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 关注歌手表 前端控制器
 * </p>
 *
 * @author
 * @since 2024-03-13
 */
@RestController
@RequestMapping("/followSinger")
public class FollowSingerController {
  @Resource
  private IFollowSingerService followSingerService;

  @PostMapping("/insert")
  public Result save(@Validated @RequestBody FollowSinger followSinger) {
    boolean result = followSingerService.save(followSinger);
    if (result) {
      return Result.success("新增成功");
    } else {
      return Result.error("新增失败");
    }
  }

  @DeleteMapping("/{id}")
  public Result delete(@PathVariable Integer id) {
    boolean result = followSingerService.removeById(id);
    if (result) {
      return Result.success("删除成功");
    } else {
      return Result.error("删除失败");
    }
  }

  //根据userId查询已经关注的歌手
  @PostMapping("/followSinger")
  public Result getFollowSingerList(@Validated @RequestBody FollowSingerPageDTO followSingerPageDTO) {
    PageInfo<User> pageInfo = followSingerService.getFollowSingerList(followSingerPageDTO);
    if (pageInfo.getData().size() > 0) {
      return Result.success("查询成功", pageInfo);
    } else {
      return Result.error("查询失败");
    }
  }

  //根据singerId查询粉丝
  @PostMapping("/fans")
  public Result getFansList(@Validated @RequestBody FansPageDTO fansPageDTO) {
    PageInfo<User> pageInfo = followSingerService.getFansList(fansPageDTO);
    if (pageInfo.getData().size() > 0) {
      return Result.success("查询成功", pageInfo);
    } else {
      return Result.error("查询失败");
    }
  }

  //取消关注
  @PostMapping("/delete")
  public Result deleteFollowSinger(@Validated @RequestBody FollowSinger followSinger){
    boolean result = followSingerService.deleteFollowSinger(followSinger);
    if (result){
      return Result.success("删除成功",null);
    }else{
      return Result.error("删除失败");
    }
  }
}

